package com.bigwolf.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * 监控权限配置
 * 
 * @author fafi
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfigurer
{
    private static final String adminContextPath = "pe";

//    public WebSecurityConfigurer(AdminServerProperties adminServerProperties)
//    {
//        this.adminContextPath = adminServerProperties.getContextPath();
//    }

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception
    {
        httpSecurity
                .csrf(csrf -> csrf.disable())
                .authorizeHttpRequests(authorize -> authorize
                        .requestMatchers("/*.html",
                                "/*/*.html",
                                "/favicon.ico",
                                "/static/**",
                                "/error/**",
                                "/*/*.css",
                                "/*/*.js",
                                "/druid/**",
                                //"/auth/**",
                                "/actuator/**")
                        .permitAll()
                        //.requestMatchers("/anth/**").permitAll()  //
                        //.requestMatchers("/login","/captchaImage","/getRouters")
                        .requestMatchers("/login","/captchaImage","/test")
                        .anonymous()
                        .anyRequest()
                        .authenticated());

//        httpSecurity
//                //.csrf(csrf -> csrf.disable())
//                .authorizeHttpRequests(authorize -> authorize.anyRequest().permitAll());
        //退出登录
        //httpSecurity.logout(logout -> logout.logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler));
        // 添加JWT filter
        //httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
        // 添加CORS filter
        //httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class);
        return httpSecurity.build();
    }
}
